import { store } from "@/store"
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { showError } from '@/utils/msg-show'
import { getAllApi } from '@/api/sys/videoConfig'

export const useVideoConfigStore = defineStore("VideoConfig", () => {

	const isZero = ref(true)
    const dataList = ref<any[]>([])


	/** 获取默认配置 */
	async function getList(){
		await getAllApi().then((res: any) => {
			dataList.value = res.data
		}).catch(err => {
			showError(err.msg || err.errMsg || err)
		})
	}

	/** 初始化 */
	async function init() {
		if (isZero.value) {
            await getList()
			isZero.value = false
		}
	}

   
	return {
		init, getList,
        dataList,
	}

})

export function useVideoConfigStoreHook() {
	return useVideoConfigStore(store);
}